"""
This script creates the 'Table of Contents'. This script MUST be ran after all other generating scripts.
"""

from {{ module.lower() }} import {{ module }}
from rstgen import *
import os, re

# Get dirs
html_dir = {{ module }}.get_html_directory()

src_dir = os.path.normpath(html_dir +'/source')
os.chdir(html_dir)

# Generate the root index directory.
create_index("Welcome to "+{{ module }}.get_current_profile()+"'s Results", src_dir, exclude=['reogo', '_templates', '_static'], depth=2)

create_index("**Help**", os.path.normpath(src_dir+'/help'))

# Get sub directories (minus standard folders)
dirs  = list(set([d for d in os.listdir(src_dir) if os.path.isdir(src_dir+'/'+d)]) - set(['reogo', '_templates', '_static']))

# create indexes for each sub dir
for d in sorted(dirs):

	# if dir is a test date
	if re.search(r'^\d{8}$', d):
		create_index("Note Index", src_dir+'/'+d+"/notes")

print "Done."

